# Maintainer: Daniel M. Capella <polyzen@archlinux.org>

_name=rstcheck_core
pkgname=python-rstcheck-core
pkgver=1.0.3
pkgrel=2
pkgdesc='Checks syntax of reStructuredText and code blocks nested within it'
arch=('any')
url=https://github.com/rstcheck/rstcheck-core
license=('MIT')
depends=('python-docutils' 'python-pydantic' 'python-typing_extensions')
makedepends=('python-build' 'python-installer' 'python-poetry-core')
checkdepends=('python-pytest' 'python-pytest-mock' 'python-sphinx')
optdepends=('python-sphinx: for Sphinx support'
            'python-tomli: for pyproject.toml support')
source=("https://files.pythonhosted.org/packages/source/${_name::1}/$_name/$_name-$pkgver.tar.gz")
sha256sums=('add19c9a1b97d9087f4b463b49c12cd8a9c03689a255e99089c70a2692f16369')
b2sums=('df7efd50fa7b5acd5e1a8a3c1a16252d8a8c59a1632b463bdeed6fc14f0c655e4bf831e1e10a04a8701da2e3efd734dca6e9ac9ced6e7df8270d1e56063bb7c6')

prepare() {
  cd $_name-$pkgver
  # Remove include list https://github.com/pypa/wheel/issues/92
  sed -i '/^include =/d' pyproject.toml
}

build() {
  cd $_name-$pkgver
  python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
 cd $_name-$pkgver
  python -m venv --system-site-packages test-env
  test-env/bin/python -m installer dist/*.whl
  PATH="$PWD/test-env/bin:$PATH" test-env/bin/python -m pytest
}

package() {
  cd $_name-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl

  # Symlink license file
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  install -d "$pkgdir"/usr/share/licenses/$pkgname
  ln -s "$site_packages"/$_name-$pkgver.dist-info/LICENSE \
    "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}
